package com.ruoyi.bigbase.service.impl;

import java.util.List;

import com.ruoyi.bigbase.mapper.CustomerMapper;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bigbase.mapper.IdentityVerificationMapper;
import com.ruoyi.bigbase.domain.IdentityVerification;
import com.ruoyi.bigbase.service.IIdentityVerificationService;

/**
 * 用户实名认证Service业务层处理
 * 
 * @author bigbase
 * @date 2025-05-10
 */
@Service
public class IdentityVerificationServiceImpl implements IIdentityVerificationService 
{
    @Autowired
    private IdentityVerificationMapper identityVerificationMapper;

    @Autowired
    private CustomerMapper customerMapper;
    /**
     * 查询用户实名认证
     * 
     * @param id 用户实名认证主键
     * @return 用户实名认证
     */
    @Override
    public IdentityVerification selectIdentityVerificationById(Long id)
    {
        return identityVerificationMapper.selectIdentityVerificationById(id);
    }

    /**
     * 查询用户实名认证列表
     * 
     * @param identityVerification 用户实名认证
     * @return 用户实名认证
     */
    @Override
    public List<IdentityVerification> selectIdentityVerificationList(IdentityVerification identityVerification)
    {
        return identityVerificationMapper.selectIdentityVerificationList(identityVerification);
    }

    /**
     * 新增用户实名认证
     * 
     * @param identityVerification 用户实名认证
     * @return 结果
     */
    @Override
    public int insertIdentityVerification(IdentityVerification identityVerification)
    {
        identityVerification.setCreateTime(DateUtils.getNowDate());
        return identityVerificationMapper.insertIdentityVerification(identityVerification);
    }

    /**
     * 修改用户实名认证
     * 
     * @param identityVerification 用户实名认证
     * @return 结果
     */
    @Override
    public int updateIdentityVerification(IdentityVerification identityVerification)
    {
        if(identityVerification.getStatus()==1){
            customerMapper.updateCustomerStatus(Math.toIntExact(identityVerification.getUid()),1);
        }
        identityVerification.setUpdateTime(DateUtils.getNowDate());
        return identityVerificationMapper.updateIdentityVerification(identityVerification);
    }

    /**
     * 批量删除用户实名认证
     * 
     * @param ids 需要删除的用户实名认证主键
     * @return 结果
     */
    @Override
    public int deleteIdentityVerificationByIds(Long[] ids)
    {
        return identityVerificationMapper.deleteIdentityVerificationByIds(ids);
    }

    /**
     * 删除用户实名认证信息
     * 
     * @param id 用户实名认证主键
     * @return 结果
     */
    @Override
    public int deleteIdentityVerificationById(Long id)
    {
        return identityVerificationMapper.deleteIdentityVerificationById(id);
    }

    @Override
    public IdentityVerification selectIdentityVerificationByUserId(Long userId) {
        return identityVerificationMapper.selectIdentityVerificationByUserId(userId);
    }
}
